<?php
/**
 * +----------------------------------------------------------------------
 * | 九月科技-ztuc.cn
 * +----------------------------------------------------------------------
 *                      .::::.
 *                    .::::::::.            | AUTHOR: siyu
 *                    :::::::::::           | EMAIL: ztucke@ztuc.cn
 *                 ..:::::::::::'           | DATETIME: 2020/01/31
 *             '::::::::::::'
 *                .::::::::::
 *           '::::::::::::::..
 *                ..::::::::::::.
 *              ``::::::::::::::::
 *               ::::``:::::::::'        .:::.
 *              ::::'   ':::::'       .::::::::.
 *            .::::'      ::::     .:::::::'::::.
 *           .:::'       :::::  .:::::::::' ':::::.
 *          .::'        :::::.:::::::::'      ':::::.
 *         .::'         ::::::::::::::'         ``::::.
 *     ...:::           ::::::::::::'              ``::.
 *   ```` ':.          ':::::::::'                  ::::..
 *                      '.:::::'                    ':'````..
 * +----------------------------------------------------------------------
 */
/**
/**
 * Created by PhpStorm.
 * UserScoreLog: Administrator
 * Date: 2020/3/14
 * Time: 17:18
 */
namespace app\lnadmin\controller;
use app\core\InitController;
use think\facade\View;
use app\lnadmin\model\admin\UserScoreLog as Score;

class UserScoreLog extends InitController
{

    // 列表
    public function list()
    {
        return View::fetch('UserScoreLog');
    }

    // 新增
    public function add()
    {
        $add = $this->request->post();
        $res = Score::add($add);
        return $res ? $this->saveSuccess() : $this->error();
    }

    // 数据 
     public function info()
    {
        $page = $this->request->get('page');
        $limit = $this->request->get('limit');
        $data = Score::lists($page, $limit);
        return $this->success($data['data'], $data['count']);
    }
   //列表详情 // 详情
    public function index_json($limit='15')
    {
        $UserScoreLog = new Score();
        $data = $UserScoreLog->order('id desc')->paginate($limit);

         // 获取用户信息
        if (!empty($data)) {
            foreach ($data as $k => $v) {
                if ($v['user_id']){
                    $userInfo = \app\lnadmin\model\admin\User::findUser($v['user_id']);
                    $data[$k]['username'] = isset($userInfo['username'])?$userInfo['username']:"";
                }
            }
        }
        $this->result($data);
    }


    // 编辑
    public function edit()
    {
        $post = $this->request->post();
        $edit = Score::edit($post);
        return $edit ? $this->saveSuccess() : $this->error();
    }

    // 删除
    public function del()
    { 
        if ($this->request->isPost()) { 
            $param = $this->request->param();
            $result = Score::destroy($param['id']);
            if ($result == true) {
                return $this->success('', '', '删除成功');
            }
        }
    }
}